<?php
	
function list_jenis(){

//PASANG JAVASCRIPT
my_set_code_js('

function confirmDelete(id){
	var t = confirm(\'Yakin akan menghapus data ?\');
	if(t){
		location.href=\'index.php?com='.$_GET['com'].'&task=delete&id=\'+id;
	}
	return false;
}

');
	$header = array(
		'#'=>array('style'=>'text-align:center;border-bottom:2px solid;width:10%'),  
		'Jenis'=>array('style'=>'border-bottom:2px solid;width:35%'), 
		'Golongan'=>array('style'=>'border-bottom:2px solid;width:35%'), 
		' '=>array('style'=>'border-bottom:2px solid;width:20%'), 
	);

	$query = "SELECT * FROM spd_jenis_non_karyawan";
	$result = my_query($query);
	$i = 0;
	$row=array();
	while($ey = my_fetch_array($result)){
		$i++;
		$editproperty = array(
						'href'=>'index.php?com='.$_GET['com'].'&task=edit&id='.$ey['jenis_non_karyawan_id'],
						'rel'=>'facebox',
						'title'=>'Edit'
				);
		$edit_button = button_icon( 'b_edit.png' , $editproperty  );

		$golproperty = array(
						'href'=>'index.php?com='.$_GET['com'].'&task=list_golongan&jid='.$ey['jenis_non_karyawan_id'],
						'title'=>'Golongan'
				);
		$gol_button = button_icon( 'b_props.png' , $golproperty  );
		$tarifproperty = array(
						'href'=>'index.php?com='.$_GET['com'].'&task=list_tarif&jid='.$ey['jenis_non_karyawan_id'],
						'title'=>'Tarif Khusus'
				);
		$tarif_button = button_icon( 'b_browse.png' , $tarifproperty  );
		$keperluanproperty = array(
						'href'=>'index.php?com='.$_GET['com'].'&task=list_keperluan&jid='.$ey['jenis_non_karyawan_id'],
						'title'=>'Keperluan'
				);
		$keperluan_button = button_icon( 'b_ftext.png' , $keperluanproperty  );
		$kendaraanproperty = array(
						'href'=>'index.php?com='.$_GET['com'].'&task=list_kendaraan&jid='.$ey['jenis_non_karyawan_id'],
						'title'=>'Kendaraan'
				);
		$kendaraan_button = button_icon( 'b_bookmark.png' , $kendaraanproperty  );

		$deleteproperty = array(
						'href'=>'javascript:; ',
						'onclick'=>'javascript:confirmDelete('.$ey['devisi_id'].');',
						'title'=>'Delete'
				);
		$delete_button = button_icon( 'b_drop.png' , $deleteproperty  );
	
		$gol_jenis='';
		$query="SELECT b.kode_golongan_jabatan FROM spd_non_karyawan_gol a
			LEFT JOIN golongan_jabatan b ON b.golongan_jabatan_id=a.golongan_jabatan_id 
			WHERE a.jenis_non_karyawan_id=".$ey['jenis_non_karyawan_id']; 
		$dres = my_query($query);	
		while($es = my_fetch_array($dres)){	
			$gol_jenis.=','.$es['kode_golongan_jabatan'];
		}
		$gol_jenis=substr($gol_jenis,1);
		$row[] = array(
			'#'=>position_text_align ($i, 'center'), 
			'divisi'=>  $ey['label_jenis_non_karyawan'] ,   
			'gol_jenis'=>  $gol_jenis,   
			'operasi'=> position_text_align(  $edit_button.' '.$gol_button.' '.$tarif_button.' '.$keperluan_button.' '.$kendaraan_button.' '.$delete_button , 'right'),  
		);
		 
	}
	
	$datas = table_rows($row);   
	return table_builder($header , $datas ,  3 , false );
}

function form_validate($id){
	$errsubmit = false;
	$err = array();  

	$code =  trim($_POST["nama"]); 
	if( $code == ''){
		$errsubmit = true;
		$err[] = "Jenis belum di isi";
	}
	$query="SELECT jenis_non_karyawan_id FROM spd_jenis_non_karyawan 
		WHERE label_jenis_non_karyawan='".$code.
		"' AND jenis_non_karyawan_id<>".$id; 
	if (my_num_rows( my_query($query)) >0){
		$errsubmit = true;
		$err[] = "Jenis sudah ada";	
	}	
	
	if( $errsubmit){
		return $err;
	}
	
	return $errsubmit;
}

function form_jenis_submit($id){
	$datas = array(
		'label_jenis_non_karyawan'=>my_type_data_str( $_POST['nama'] ), 
	);
	if($id > 0){
		return my_update_record('spd_jenis_non_karyawan' ,'jenis_non_karyawan_id' , $id , $datas);
	}
	
	return my_insert_record('spd_jenis_non_karyawan' , $datas);
}

function form_jenis_create($id = 0){
	$view = form_header( "spd_jenis_non_karyawan" , "spd_jenis_non_karyawan"  );
 	$fields = my_get_data_by_id('spd_jenis_non_karyawan','jenis_non_karyawan_id',$id);
	$nama = array(
				'name'=>'nama',
				'value'=>( isset($_POST['nama']) ? $_POST['nama'] : $fields['label_jenis_non_karyawan'] ),
				'id'=>'nama',
				'type'=>'text',
				'size'=>'45'
			);
	$form_field_nama = form_dynamic($nama);
	
	$view .= form_field_display( $form_field_nama   , "Jenis"   );
	
		$submit = array(
		'value' => ( $id ==0 ? ' Simpan ' :'  Update  '),
		'name' => 'simpan', 
		'type'=>'submit','class'=>'main_button'
	);
	$form_submit= form_dynamic($submit); 
	
	$view .= form_field_display( $form_submit  , "&nbsp;" ,  "" );
	$view .= form_footer( );
	return $view;
}
function remove_devisi($id){
	$query= "DELETE FROM spd_jenis_non_karyawan WHERE  jenis_non_karyawan_id = {$id}";
	return my_query($query);
} 
 

/*  
==================================================================
 JENIS NON KARYAWAN - GOLONGAN JABATAN
==================================================================
*/

function list_golongan($jid){
	my_set_code_js('
		function confirmDelete(id){
			var t = confirm(\'Yakin akan menghapus data ?\');
			if(t){
				location.href=\'index.php?com='.$_GET['com'].'&task=golongan_delete&id=\'+id;
			}
			return false;
		}
	');

	$header = array(
		'#'=>array('style'=>'border-bottom:2px solid;width:5%'),  
		'Golongan Jabatan'=>array('style'=>'border-bottom:2px solid;width:85%'),  
		' '=>array('style'=>'border-bottom:2px solid;width:10%'), 
	);

	$query = "SELECT * FROM spd_non_karyawan_gol where jenis_non_karyawan_id=".$jid;
	$result = my_query($query);
	$i = 0;
	$row=array();
	while($ey = my_fetch_array($result)){
		$i++;
		$editproperty = array(
			'href'=>'index.php?com='.$_GET['com'].'&task=golongan_create&jid='.$jid.'&id='.$ey['spd_non_karyawan_gol_id'],
			'rel'=>'facebox',
			'title'=>'Edit'
		);
		$edit_button = button_icon( 'b_edit.png' , $editproperty  );

		$deleteproperty = array(
				'href'=>'javascript:;',
				'title'=>'Delete',
				'onclick'=>'confirmDelete('.$ey['spd_non_karyawan_gol_id'].')',
			);
			$delete_button = button_icon( 'b_drop.png' , $deleteproperty  );
		
		$golongan_jabatan =my_get_data_by_id('golongan_jabatan','golongan_jabatan_id',$ey['golongan_jabatan_id']);
		$row[] = array(
			'#'=>position_text_align ($i, 'center'), 
			'Golongan Jabatan'=>  $golongan_jabatan['kode_golongan_jabatan'] ,   
			'operasi'=> position_text_align(  $edit_button.' '.$delete_button, 'right'),  
		);
		 
	}
	$datas = table_rows($row);   
	$jeniss = my_get_data_by_id('spd_jenis_non_karyawan','jenis_non_karyawan_id',$jid); 	 
	$view ='<table width="90%" cellspacing="0" cellpadding="4"><tr>'; 
	$view .= form_header( "Unit grievance" , "Unit grievance"  );
	$view .= form_field_display( '<span class="label_form">'.ucfirst($jeniss['label_jenis_non_karyawan']).'</span>', "<b>Jenis Karyawan</b>"    ); 
	
	return $view.table_builder($header , $datas ,  3 , false );
} 

function form_golongan_create($jid,$id = 0){
	$view = form_header( "grievance_kelompok" , "grievance_kelompok"  );
 	$fields = my_get_data_by_id('spd_non_karyawan_gol','spd_non_karyawan_gol_id',$id);
	 
	$gols = array();
	 $query_golongan = "SELECT * FROM golongan_jabatan ORDER BY kode_golongan_jabatan";
	 $re = my_query($query_golongan);
	 while($row = my_fetch_array($re) ){
		$gols[$row['golongan_jabatan_id']] =$row['kode_golongan_jabatan'];
	 }
	 $gol = array(
		'name'=>'golongan_jabatan_id',
		'id'=>'golongan_jabatan_id',
		'value'=>isset($_POST['golongan_jabatan_id']) ? $_POST['golongan_jabatan_id'] : $fields['golongan_jabatan_id'] 
		);
	$form_field_gol = form_dropdown($gol , $gols);
	$view .= form_field_display( $form_field_gol   , "Golongan Jabatan");

	
	$submit = array(
		'value' => ( $id ==0 ? ' Simpan ' :'  Update  '),
		'name' => 'simpan', 
		'type'=>'submit','class'=>'main_button'
	);
	$form_submit= form_dynamic($submit); 
	
	$view .= form_field_display( $form_submit  , "&nbsp;" ,  "" );
	$view .= form_footer( );
	return $view;
} 

	 
function form_golongan_submit($jid,$id=0){
	$datas = array(
		'jenis_non_karyawan_id'=>my_type_data_int($jid),
		'golongan_jabatan_id'=>my_type_data_str( $_POST['golongan_jabatan_id'] ),
	);
	if($id > 0){
		return my_update_record('spd_non_karyawan_gol' ,'spd_non_karyawan_gol_id' , $id , $datas);
	}
	
	return my_insert_record('spd_non_karyawan_gol' , $datas);
} 

function form_golongan_validate($jid,$id){
	$errsubmit = false;
	$err = array();


	$code =  trim($_POST["golongan_jabatan_id"]); 
	if( $code == '0'){
		$errsubmit = true;
		$err[] = "Golongan Jabatan belum diisi";
	}

	$query="SELECT spd_non_karyawan_gol_id FROM spd_non_karyawan_gol 
		WHERE golongan_jabatan_id=".$code.
		" AND jenis_non_karyawan_id=".$jid. 
		" AND spd_non_karyawan_gol_id<>".$id; 
	if (my_num_rows( my_query($query)) >0){
		$errsubmit = true;
		$err[] = "Golongan Jabatan sudah ada";	
	}
  
	if( $errsubmit){
		return $err;
	}
	return $errsubmit;
}

function delete_golongan($id){
	$query = "DELETE FROM spd_non_karyawan_gol WHERE spd_non_karyawan_gol_id ={$id} ";
	return my_query($query);
}


/*  
==================================================================
 JENIS NON KARYAWAN - TARIF KHUSUS
==================================================================
*/

function list_tarif($jid){
	my_set_code_js('
		function confirmDelete(id){
			var t = confirm(\'Yakin akan menghapus data ?\');
			if(t){
				location.href=\'index.php?com='.$_GET['com'].'&task=tarif_delete&jid='.$jid.'&id=\'+id;
			}
			return false;
		}
	');

	$header = array(
		'#'=>array('style'=>'border-bottom:2px solid;width:5%'),  
		'Keperluan'=>array('style'=>'border-bottom:2px solid;width:20%'),  
		'Komponen Biaya'=>array('style'=>'border-bottom:2px solid;width:45%'),  
		'Biaya per hari'=>array('style'=>'text-align:right;border-bottom:2px solid;width:20%'),  
		' '=>array('style'=>'border-bottom:2px solid;width:10%'), 
	);

	$query = "SELECT * FROM spd_jenis_non_karyawan_biaya a 
		INNER JOIN spd_biaya b ON a.biaya_id=b.biaya_id 
		INNER JOIN spd_keperluan c ON a.keperluan_id=c.keperluan_id 
		where jenis_non_karyawan_id=".$jid;
	$result = my_query($query);
	$i = 0;
	$row=array();
	while($ey = my_fetch_array($result)){
		$i++;
		$editproperty = array(
			'href'=>'index.php?com='.$_GET['com'].'&task=form_tarif&jid='.$jid.'&id='.$ey['jenis_non_karyawan_biaya_id'],
			'rel'=>'facebox',
			'title'=>'Edit'
		);
		$edit_button = button_icon( 'b_edit.png' , $editproperty  );

		$deleteproperty = array(
			'href'=>'javascript:;',
			'title'=>'Delete',
			'onclick'=>'confirmDelete('.$ey['jenis_non_karyawan_biaya_id'].')',
		);
		$delete_button = button_icon( 'b_drop.png' , $deleteproperty  );
		
		$row[] = array(
			'#'=>position_text_align ($i, 'center'), 
			'Keperluan'=>  $ey['label_keperluan'] , 
			'Komponen Biaya'=>  $ey['label_biaya'] , 
			'tarif'=> position_text_align( rp_format($ey['nominal']) ,  'right'), 			
			'operasi'=> position_text_align(  $edit_button.' '.$delete_button, 'right'),  
		);
		 
	}
	$datas = table_rows($row);   
	$jeniss = my_get_data_by_id('spd_jenis_non_karyawan','jenis_non_karyawan_id',$jid); 	 
	$view ='<table width="90%" cellspacing="0" cellpadding="4"><tr>'; 
	$view .= form_header( "Unit grievance" , "Unit grievance"  );
	$view .= form_field_display( '<span class="label_form">'.ucfirst($jeniss['label_jenis_non_karyawan']).'</span>', "<b>Jenis Karyawan</b>"    ); 
	
	return $view.table_builder($header , $datas ,  3 , false );
} 

function form_tarif($jid,$id = 0){
	$view = form_header( "grievance_kelompok" , "grievance_kelompok"  );
 	$fields = my_get_data_by_id('spd_jenis_non_karyawan_biaya','jenis_non_karyawan_biaya_id',$id);

	$atemps = array();
	$query = "SELECT * FROM spd_keperluan ORDER BY label_keperluan";
	$re = my_query($query);
	while($row = my_fetch_array($re) ){
		$atemps[$row['keperluan_id']] =$row['label_keperluan'];
	}
	$temp = array(
		'name'=>'keperluan_id',
		'id'=>'keperluan_id',
		'value'=>isset($_POST['keperluan_id']) ? $_POST['keperluan_id'] : $fields['keperluan_id'] 
		);
	$form_temp = form_dropdown($temp , $atemps);
	$view .= form_field_display( $form_temp   , "Keperluan");

	$atemps = array();
	$query = "SELECT * FROM spd_biaya ORDER BY label_biaya";
	$re = my_query($query);
	while($row = my_fetch_array($re) ){
		$atemps[$row['biaya_id']] =$row['label_biaya'];
	}
	$temp = array(
		'name'=>'biaya_id',
		'id'=>'biaya_id',
		'value'=>isset($_POST['biaya_id']) ? $_POST['biaya_id'] : $fields['biaya_id'] 
		);
	$form_temp = form_dropdown($temp , $atemps);
	$view .= form_field_display( $form_temp   , "Komponen Biaya");
	$temp = array(
		'name'=>'nominal',
		'value'=>( isset($_POST['nominal']) ? $_POST['nominal'] : rp_format($fields['nominal']) ),
		'id'=>'nominal',
		'type'=>'text',
		'size'=>'25'
	);
	$form_temp = form_dynamic($temp);
	$view .= form_field_display( $form_temp  , "Nominal" );		
	$submit = array(
		'value' => ( $id ==0 ? ' Simpan ' :'  Update  '),
		'name' => 'simpan', 
		'type'=>'submit','class'=>'main_button'
	);
	$form_submit= form_dynamic($submit); 
	$view .= form_field_display( $form_submit  , "&nbsp;" ,  "" );
	$view .= form_footer( );
	return $view;
} 

function tarif_validate($jid,$id){
	$errsubmit = false;
	$err = array();
	$code =  trim($_POST["biaya_id"]); 
	if( $code == '0'){
		$errsubmit = true;
		$err[] = "Komponen Biaya belum diisi";
	}
	/*
	$query="SELECT jenis_non_karyawan_biaya_id FROM spd_jenis_non_karyawan_biaya 
		WHERE biaya_id=".$code.
		" AND jenis_non_karyawan_id=".$jid. 
		" AND jenis_non_karyawan_biaya_id<>".$id; 
	
		
	if (my_num_rows( my_query($query)) >0){
		$errsubmit = true;
		$err[] = "Komponen Biaya sudah ada";	
	} 
	*/	
	if( $errsubmit){
		return $err;
	}
	return $errsubmit;
}
	 
function tarif_submit($jid,$id=0){
	$datas = array(
		'jenis_non_karyawan_id'=>my_type_data_int($jid),
		'keperluan_id'=>my_type_data_int( $_POST['keperluan_id'] ),
		'biaya_id'=>my_type_data_int( $_POST['biaya_id'] ),
		'nominal'=>my_type_data_str( set_text_as_number($_POST['nominal']) ),
	);
	if($id > 0){
		return my_update_record('spd_jenis_non_karyawan_biaya' ,'jenis_non_karyawan_biaya_id' , $id , $datas);
	}
	
	return my_insert_record('spd_jenis_non_karyawan_biaya' , $datas);
} 



function delete_tarif($id){
	$query = "DELETE FROM spd_jenis_non_karyawan_biaya WHERE jenis_non_karyawan_biaya_id ={$id} ";
	return my_query($query);
}		 


/*  
==================================================================
 JENIS NON KARYAWAN - KEPERLUAN KHUSUS
==================================================================
*/

function list_keperluan($jid){
	my_set_code_js('
		function confirmDelete(id){
			var t = confirm(\'Yakin akan menghapus data ?\');
			if(t){
				location.href=\'index.php?com='.$_GET['com'].'&task=keperluan_delete&jid='.$jid.'&id=\'+id;
			}
			return false;
		}
	');

	$header = array(
		'#'=>array('style'=>'border-bottom:2px solid;width:5%'),  
		'Keperluan'=>array('style'=>'border-bottom:2px solid;width:85%'),  
		' '=>array('style'=>'border-bottom:2px solid;width:10%'), 
	);

	$query = "SELECT * FROM spd_jenis_non_karyawan_keperluan a 
		INNER JOIN spd_keperluan c ON a.keperluan_id=c.keperluan_id 
		where jenis_non_karyawan_id=".$jid;
	$result = my_query($query);
	$i = 0;
	$row=array();
	while($ey = my_fetch_array($result)){
		$i++;
		$editproperty = array(
			'href'=>'index.php?com='.$_GET['com'].'&task=form_keperluan&jid='.$jid.'&id='.$ey['jenis_non_karyawan_keperluan_id'],
			'rel'=>'facebox',
			'title'=>'Edit'
		);
		$edit_button = button_icon( 'b_edit.png' , $editproperty  );

		$deleteproperty = array(
			'href'=>'javascript:;',
			'title'=>'Delete',
			'onclick'=>'confirmDelete('.$ey['jenis_non_karyawan_keperluan_id'].')',
		);
		$delete_button = button_icon( 'b_drop.png' , $deleteproperty  );
		
		$row[] = array(
			'#'=>position_text_align ($i, 'center'), 
			'Keperluan'=>  $ey['label_keperluan'] , 
			'operasi'=> position_text_align(  $edit_button.' '.$delete_button, 'right'),  
		);
		 
	}
	$datas = table_rows($row);   
	$jeniss = my_get_data_by_id('spd_jenis_non_karyawan','jenis_non_karyawan_id',$jid); 	 
	$view ='<table width="90%" cellspacing="0" cellpadding="4"><tr>'; 
	$view .= form_header( "Unit grievance" , "Unit grievance"  );
	$view .= form_field_display( '<span class="label_form">'.ucfirst($jeniss['label_jenis_non_karyawan']).'</span>', "<b>Jenis Karyawan</b>"    ); 
	
	return $view.table_builder($header , $datas ,  3 , false );
} 

function form_keperluan($jid,$id = 0){
	$view = form_header( "grievance_kelompok" , "grievance_kelompok"  );
 	$fields = my_get_data_by_id('spd_jenis_non_karyawan_keperluan','jenis_non_karyawan_keperluan_id',$id);

	$atemps = array();
	$query = "SELECT * FROM spd_keperluan ORDER BY label_keperluan";
	$re = my_query($query);
	while($row = my_fetch_array($re) ){
		$atemps[$row['keperluan_id']] =$row['label_keperluan'];
	}
	$temp = array(
		'name'=>'keperluan_id',
		'id'=>'keperluan_id',
		'value'=>isset($_POST['keperluan_id']) ? $_POST['keperluan_id'] : $fields['keperluan_id'] 
		);
	$form_temp = form_dropdown($temp , $atemps);
	$view .= form_field_display( $form_temp   , "Keperluan");
	$submit = array(
		'value' => ( $id ==0 ? ' Simpan ' :'  Update  '),
		'name' => 'simpan', 
		'type'=>'submit','class'=>'main_button'
	);
	$form_submit= form_dynamic($submit); 
	$view .= form_field_display( $form_submit  , "&nbsp;" ,  "" );
	$view .= form_footer( );
	return $view;
} 

function keperluan_validate($jid,$id){
	$errsubmit = false;
	$err = array();
	$code =  trim($_POST["keperluan_id"]); 
	if( $code == '0'){
		$errsubmit = true;
		$err[] = "Keperluan belum diisi";
	}
	/*
	$query="SELECT jenis_non_karyawan_biaya_id FROM spd_jenis_non_karyawan_biaya 
		WHERE biaya_id=".$code.
		" AND jenis_non_karyawan_id=".$jid. 
		" AND jenis_non_karyawan_biaya_id<>".$id; 
	
		
	if (my_num_rows( my_query($query)) >0){
		$errsubmit = true;
		$err[] = "Komponen Biaya sudah ada";	
	} 
	*/	
	if( $errsubmit){
		return $err;
	}
	return $errsubmit;
}
	 
function keperluan_submit($jid,$id=0){
	$datas = array(
		'jenis_non_karyawan_id'=>my_type_data_int($jid),
		'keperluan_id'=>my_type_data_int( $_POST['keperluan_id'] ),
	);
	if($id > 0){
		return my_update_record('spd_jenis_non_karyawan_keperluan' ,'jenis_non_karyawan_keperluan_id' , $id , $datas);
	}
	
	return my_insert_record('spd_jenis_non_karyawan_keperluan' , $datas);
} 



function delete_keperluan($id){
	$query = "DELETE FROM spd_jenis_non_karyawan_keperluan WHERE jenis_non_karyawan_keperluan_id ={$id} ";
	return my_query($query);
}		


/*  
==================================================================
 JENIS NON KARYAWAN - KENDARAAN KHUSUS
==================================================================
*/

function list_kendaraan($jid){
	my_set_code_js('
		function confirmDelete(id){
			var t = confirm(\'Yakin akan menghapus data ?\');
			if(t){
				location.href=\'index.php?com='.$_GET['com'].'&task=kendaraan_delete&jid='.$jid.'&id=\'+id;
			}
			return false;
		}
	');

	$header = array(
		'#'=>array('style'=>'border-bottom:2px solid;width:5%'),  
		'Kendaraan'=>array('style'=>'border-bottom:2px solid;width:85%'),  
		' '=>array('style'=>'border-bottom:2px solid;width:10%'), 
	);

	$query = "SELECT * FROM spd_jenis_non_karyawan_kendaraan a 
		INNER JOIN spd_kendaraan c ON a.kendaraan_id=c.kendaraan_id 
		where jenis_non_karyawan_id=".$jid;
	$result = my_query($query);
	$i = 0;
	$row=array();
	while($ey = my_fetch_array($result)){
		$i++;
		$editproperty = array(
			'href'=>'index.php?com='.$_GET['com'].'&task=form_kendaraan&jid='.$jid.'&id='.$ey['jenis_non_karyawan_kendaraan_id'],
			'rel'=>'facebox',
			'title'=>'Edit'
		);
		$edit_button = button_icon( 'b_edit.png' , $editproperty  );

		$deleteproperty = array(
			'href'=>'javascript:;',
			'title'=>'Delete',
			'onclick'=>'confirmDelete('.$ey['jenis_non_karyawan_kendaraan_id'].')',
		);
		$delete_button = button_icon( 'b_drop.png' , $deleteproperty  );
		
		$row[] = array(
			'#'=>position_text_align ($i, 'center'), 
			'kendaraan'=>  $ey['label_kendaraan'] , 
			'operasi'=> position_text_align(  $edit_button.' '.$delete_button, 'right'),  
		);
		 
	}
	$datas = table_rows($row);   
	$jeniss = my_get_data_by_id('spd_jenis_non_karyawan','jenis_non_karyawan_id',$jid); 	 
	$view ='<table width="90%" cellspacing="0" cellpadding="4"><tr>'; 
	$view .= form_header( "Unit grievance" , "Unit grievance"  );
	$view .= form_field_display( '<span class="label_form">'.ucfirst($jeniss['label_jenis_non_karyawan']).'</span>', "<b>Jenis Karyawan</b>"    ); 
	
	return $view.table_builder($header , $datas ,  3 , false );
} 

function form_kendaraan($jid,$id = 0){
	$view = form_header( "grievance_kelompok" , "grievance_kelompok"  );
 	$fields = my_get_data_by_id('spd_jenis_non_karyawan_kendaraan','jenis_non_karyawan_kendaraan_id',$id);

	$atemps = array();
	$query = "SELECT * FROM spd_kendaraan ORDER BY label_kendaraan";
	$re = my_query($query);
	while($row = my_fetch_array($re) ){
		$atemps[$row['kendaraan_id']] =$row['label_kendaraan'];
	}
	$temp = array(
		'name'=>'kendaraan_id',
		'id'=>'kendaraan_id',
		'value'=>isset($_POST['kendaraan_id']) ? $_POST['kendaraan_id'] : $fields['kendaraan_id'] 
		);
	$form_temp = form_dropdown($temp , $atemps);
	$view .= form_field_display( $form_temp   , "Kendaraan");
	$submit = array(
		'value' => ( $id ==0 ? ' Simpan ' :'  Update  '),
		'name' => 'simpan', 
		'type'=>'submit','class'=>'main_button'
	);
	$form_submit= form_dynamic($submit); 
	$view .= form_field_display( $form_submit  , "&nbsp;" ,  "" );
	$view .= form_footer( );
	return $view;
} 

function kendaraan_validate($jid,$id){
	$errsubmit = false;
	$err = array();
	$code =  trim($_POST["kendaraan_id"]); 
	if( $code == '0'){
		$errsubmit = true;
		$err[] = "Kendaraan belum diisi";
	}
	/*
	$query="SELECT jenis_non_karyawan_biaya_id FROM spd_jenis_non_karyawan_biaya 
		WHERE biaya_id=".$code.
		" AND jenis_non_karyawan_id=".$jid. 
		" AND jenis_non_karyawan_biaya_id<>".$id; 
	
		
	if (my_num_rows( my_query($query)) >0){
		$errsubmit = true;
		$err[] = "Komponen Biaya sudah ada";	
	} 
	*/	
	if( $errsubmit){
		return $err;
	}
	return $errsubmit;
}
	 
function kendaraan_submit($jid,$id=0){
	$datas = array(
		'jenis_non_karyawan_id'=>my_type_data_int($jid),
		'kendaraan_id'=>my_type_data_int( $_POST['kendaraan_id'] ),
	);
	if($id > 0){
		return my_update_record('spd_jenis_non_karyawan_kendaraan' ,'jenis_non_karyawan_kendaraan_id' , $id , $datas);
	}
	
	return my_insert_record('spd_jenis_non_karyawan_kendaraan' , $datas);
} 



function delete_kendaraan($id){
	$query = "DELETE FROM spd_jenis_non_karyawan_kendaraan WHERE jenis_non_karyawan_kendaraan_id ={$id} ";
	return my_query($query);
}	

function select_all_kendaraan($jid){
	$query = "DELETE FROM spd_jenis_non_karyawan_kendaraan WHERE jenis_non_karyawan_id ={$jid} ";
	my_query($query);
	$atemps = array();
	$query = "SELECT kendaraan_id FROM spd_kendaraan";
	$re = my_query($query);
	while($row = my_fetch_array($re) ){
		$datas = array(
			'jenis_non_karyawan_id'=>my_type_data_int($jid),
			'kendaraan_id'=>my_type_data_int( $row['kendaraan_id'] ),
		);	
		my_insert_record('spd_jenis_non_karyawan_kendaraan' , $datas);
	}
	return true;
}	